package cn.ssm.test.service.impl;

import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

import cn.ssm.test.dao.IUserDao;
import cn.ssm.test.model.User;
import cn.ssm.test.service.IUserService;

@Service("userService")
public class UserServiceImpl implements IUserService {
	@Resource
	private IUserDao userDao;

	public User getUserById(int userId) {
		return userDao.queryByPrimaryKey(userId);
	}

	public void insertUser(User user) {
		userDao.insertUser(user);
	}

	public void addUser(User user) {
		userDao.insertUser(user);
	}

	@Override
	public List<User> getAllUser() {
		return userDao.getAllUser();
	}

	@Override
	public User getUserByName(String name) {
		// TODO Auto-generated method stub
		return userDao.getUserByName(name);
	}

	@Override
	public String getUserSSO(String name, String password) {
		User user = userDao.getUserByName(name);
		String token = "";
		if (user.getPassword().equals(password)) {
			token = UUID.randomUUID().toString();
			// jedisClient.set("REDIS_SESSION "+ ":" + token,JSON.toJSONString(user));
		}
		return token;
	}

}